/**将任一整数转化为二进制形式*/

#include <stdio.h>

void printb(int x, int n);
int main()
{
    int x;
    printf("Input number:");
    scanf("%d", &x);
    printf("number of decimal form: %d\n", x);
    printf("    it's binary form:");
    printb(x, sizeof(int) * 8);
    putchar('\n');
}

void printb(int x, int n)
{
    if (n > 0)
    {
        // 递归 每次获取一位上面的值， 从最高位开始
        putchar('0' + ((unsigned)(x & (1 << (n - 1))) >> (n - 1)));
        printb(x, n - 1);
    }
}